package com.hxzy.module.auth.api.fallback;

import com.hxzy.framework.common.req.CaptchaCodeReq;
import com.hxzy.framework.common.resp.CaptchaCodeResp;
import com.hxzy.framework.common.resp.R;
import com.hxzy.framework.common.resp.ResultCode;
import com.hxzy.module.auth.api.auth.AuthFeignApi;
import com.hxzy.module.auth.api.auth.resp.Oauth2TokenDto;
import feign.hystrix.FallbackFactory;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author wy
 * @Description TODO
 * @Date 2024/1/27 9:42
 * @Version 1.0
 */
@Log4j2
@Component
public class AuthFeignApiFallbackFactory implements FallbackFactory<AuthFeignApi> {
    @Override
    public AuthFeignApi create(Throwable throwable) {
        log.error(throwable);
        return new AuthFeignApiFallbackFactoryImpl();
    }

    class AuthFeignApiFallbackFactoryImpl implements AuthFeignApi{


        @Override
        public R<Oauth2TokenDto> postAccessToken(Map<String, String> parameters) {
            return R.failed(ResultCode.DEMOTION);
        }

        @Override
        public Map<String, Object> getKey() {
            return new HashMap<>();
        }

        @Override
        public R<CaptchaCodeResp> easyCaptcha(CaptchaCodeReq req) {
            return R.failed(ResultCode.DEMOTION);
        }
    }
}
